package com.book.inteliget.readMain;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RDFDistiller {

	private static final String RDFDISTILLER_URL = "http://rdf.greggkellogg.net/distiller";


	public static InputStream distillRDF(String urlString, String inputFormat, String outputFormat) throws Exception {

	if (inputFormat == null || inputFormat.equals("") )
	inputFormat = "rdfagraph";
	if ( outputFormat == null || outputFormat.equals("") )
	outputFormat = "rdfxml";

	//building url of the following form:
	//http://rdf.greggkellogg.net/distiller?format=rdfxml&rdfagraph=&uri=http://www.example.com/
	StringBuilder sb = new StringBuilder();
	sb.append(RDFDISTILLER_URL);
	sb.append("?format=").append( outputFormat + "&" + inputFormat );
	sb.append("&uri=").append( encoder.Encoder.encode(urlString) );

	URL requestURL = new URL( sb.toString() );
	HttpURLConnection conn = (HttpURLConnection)requestURL.openConnection();
	conn.setRequestMethod("GET");

	return conn.getInputStream();

	}

}
